Imports System.Data
Partial Class GTSWeb_Carrier_Manage
    Inherits System.Web.UI.Page

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click

        Dim ContractRateINFOLogic As New GTSSystem.BLL.Rates
        Dim RateData As DataTable

        'Create the table to return to the Shipment.BLL
        Dim RData As New DataTable("Rates")
        RData.Columns.Add("Rate Detail ID", GetType(Integer))
        RData.Columns.Add("Origin", GetType(String))
        RData.Columns.Add("Destination", GetType(String))
        RData.Columns.Add("Service Type", GetType(String))
        RData.Columns.Add("Minimum Weight", GetType(Double))
        RData.Columns.Add("Maximum Weight", GetType(Double))
        RData.Columns.Add("Rate Charge", GetType(Double))
        RData.Columns.Add("Base Rate", GetType(Double))
        RData.Columns.Add("Minimum Charge", GetType(Double))
        RData.Columns.Add("Rate Type", GetType(String))

        RateData = ContractRateINFOLogic.GetContractRateINFOByContractID(2)
        If RateData.Rows.Count > 0 Then
            For n As Integer = 0 To RateData.Rows.Count - 1
                Dim RateDetailID As Integer = RateData.Rows(n).Item("RateDetailID")
                Dim Origin As Integer = RateData.Rows(n).Item("Origin")
                Dim Destination As Integer = RateData.Rows(n).Item("Destination")
                Dim ServiceTypeID As Integer = RateData.Rows(n).Item("ServiceTypeID")
                Dim RateTypeID As Integer = RateData.Rows(n).Item("RateTypeID")
                Dim MinWeight As Double = RateData.Rows(n).Item("MinWeight")
                Dim MaxWeight As Double = RateData.Rows(n).Item("MaxWeight")
                Dim RateCharge As Double = 0
                Dim BaseRate As Double = 0
                Dim MinCharge As Double = 0
                If Not IsDBNull(RateData.Rows(n).Item("Price")) Then
                    RateCharge = RateData.Rows(n).Item("Price")
                End If
                If Not IsDBNull(RateData.Rows(n).Item("BaseRate")) Then
                    BaseRate = RateData.Rows(n).Item("BaseRate")
                End If
                If Not IsDBNull(RateData.Rows(n).Item("MinCharge")) Then
                    MinCharge = RateData.Rows(n).Item("MinCharge")
                End If

                'gets location names
                Dim OData As DataTable
                Dim DData As DataTable
                Dim LocationLogic As New GTSSystem.BLL.RateLocation()
                OData = LocationLogic.GetRateLocationByRateLocationID(Origin)
                DData = LocationLogic.GetRateLocationByRateLocationID(Destination)
                Dim OCity As String = OData.Rows(0).Item("City")
                Dim OProv As String = OData.Rows(0).Item("Province")
                Dim DCity As String = DData.Rows(0).Item("City")
                Dim DProv As String = DData.Rows(0).Item("Province")
                'gets service type name
                Dim STData As DataTable
                STData = GTSSystem.BLL.ServiceType.GetServiceTypeByID(ServiceTypeID)
                Dim ServiceType As String = STData.Rows(0).Item("ServiceTypeName")
                'gets rate type name
                Dim RTData As DataTable
                RTData = GTSSystem.BLL.RateType.GetRateTypeByID(RateTypeID)
                Dim RateType As String = RTData.Rows(0).Item("RateTypeName")
                Dim aRow As DataRow
                aRow = RData.NewRow
                aRow.Item("Rate Detail ID") = RateDetailID
                aRow.Item("Origin") = OCity + ", " + OProv
                aRow.Item("Destination") = DCity + ", " + DProv
                aRow.Item("Service Type") = ServiceType
                aRow.Item("Minimum Weight") = MinWeight
                aRow.Item("Maximum Weight") = MaxWeight
                aRow.Item("Rate Charge") = RateCharge
                aRow.Item("Base Rate") = BaseRate
                aRow.Item("Minimum Charge") = MinCharge
                aRow.Item("Rate Type") = RateType
                RData.Rows.Add(aRow)
            Next
            gdvwContractRates.DataSource = RData
            gdvwContractRates.DataBind()
            Message.Text = "Upload Successful: Purolator.csv"
        Else
            Message.Text = "No rates found for this contract"
        End If

    End Sub

End Class
